package agent;

import java.util.Date;

import message.CheckUserMsg;
import message.RegisterUserMsg;
import message.UserMsg;

import framework.Message;
import framework.agent.AbstractAgent;


public class UserAgent extends AbstractAgent {

	private static final String NAME = "UserAgent";
	private static UserAgent sole;

	public static UserAgent getSole() {
		if (sole == null) {
			sole = new UserAgent(NAME);
		}
		return sole;
	}

	private UserAgent(String agentName) {
		super(agentName);
	}

	@SuppressWarnings("unchecked")
	private <M extends Message> M sendAndReceiveMsg(Message msg) {
		return (M)sendAndWait(msg, "UserService");
	}

	public int checkUser(String username, String password) {
		Message request = new CheckUserMsg(getAgentName(), username, password);
		UserMsg responce = sendAndReceiveMsg(request);
		return responce.getResult();
	}

	public int registerUser(String username, String password, String email, Date birth) {
		Message request = new RegisterUserMsg(getAgentName(), username, password, email, birth);
		UserMsg responce = sendAndReceiveMsg(request);
		return responce.getResult();
	}

	public void userLogout(String loggedUser) {
		// TODO 
	}
}
